import requestMeeting from '@/plugins/axios'
import { IVideoSourceListItem } from './interface'

/** 获取终端预设位 */
export const fetchGetPosition = async (meetingMoid: string, mt_id: string) =>
	requestMeeting({
		url: `/mcc/${meetingMoid}/camera/pre_positions`,
		method: 'get',
		params: { mt_id },
	}).then((res) => res)

/** 调用终端摄像机预置位 */
export const fetchChangePosition = async (meetingMoid: string, mt_id: string, pos_id: string, name: string) =>
	requestMeeting({
		url: `/mcc/${meetingMoid}/camera/pre_position`,
		method: 'put',
		data: { mt_id, pos_id, name },
	}).then((res) => res)

/** 保存终端预设位 */
export const fetchSavePosition = async (meetingMoid: string, mt_id: string, pos_id: string) =>
	requestMeeting({
		url: `/mcc/${meetingMoid}/camera/pre_position`,
		method: 'post',
		data: { mt_id, pos_id },
	}).then((res) => res)

/** 获取指定终端的所有视频源 */
export const fetchGetVideoSource = async (meetingMoid: string, mt_id: string) =>
	requestMeeting<IVideoSourceListItem[]>({
		url: `/mcc/${meetingMoid}/camera/mt_video_source`,
		method: 'get',
		params: { mt_id },
	}).then((res) => res)

/** 获取指定终端当前视频源 */
export const fetchGetCurVideoSource = async (meetingMoid: string, mt_id: string) =>
	requestMeeting<{ mt_id: string; cur_video_src_idx: string }>({
		url: `/mcc/${meetingMoid}/camera/cur_mt_video_source`,
		method: 'get',
		params: { mt_id },
	}).then((res) => res)

/** 设置指定终端当前视频源 */
export const fetchSetVideoSource = async (meetingMoid: string, mt_id: string, video_src_idx: string) =>
	requestMeeting<{ vid_port_idx: string; vid_alias: string }[]>({
		url: `/mcc/${meetingMoid}/camera/video_source`,
		method: 'post',
		data: { mt_id, video_src_idx },
	}).then((res) => res.success)

export const fetchStartMove = async (meetingMoid: string, data: { mt_id: string; action: string }) =>
	requestMeeting({
		url: `/mcc/${meetingMoid}/camera`,
		method: 'post',
		data: data,
	}).then((res) => res)

export const fetchStopMove = async (meetingMoid: string, data: { mt_id: string; action: string }) =>
	requestMeeting({
		url: `/mcc/${meetingMoid}/camera`,
		method: 'DELETE',
		data: data,
	}).then((res) => res)
